Uploaded image for project: 'Apache Storm'
  1. Apache Storm
  2. STORM-1481

avoid Math.abs(Integer) get a negative value

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • None
    • 1.0.0, 0.10.1, 2.0.0
    • storm-core
    • None

    Description

      before fix:

      org.apache.storm.trident.partition.IndexHashGrouping
          public static int objectToIndex(Object val, int numPartitions) {
              if(val==null) return 0;
              else {
                  return Math.abs(val.hashCode()) % numPartitions;
              }
          }
      

      If the hashcode is Integer.MIN_VALUE, then the result will be negative as well (since Math.abs(Integer.MIN_VALUE) == Integer.MIN_VALUE).

      after fix:
      Use toPositive replace Math.abs:

          public static int toPositive(int number) {
              return number & Integer.MAX_VALUE;
          }
      

      Attachments

        Activity

          People

            vesense Xin Wang
            vesense Xin Wang
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: